﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Configuration;
using Windows.Foundation;
using Windows.UI;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Shapes = Windows.UI.Xaml.Shapes;

namespace BoolanElement
{
      public class BooRectangle: BooTextShapesBase
     {
          Shapes.Polygon rectangle;
         public Shapes.Polygon Rectangle
         {
             get { return rectangle; }
             set { rectangle = value; }
         }

         BooRectangleElement rectangleElement;
         public BooRectangleElement RectangleElement 
         {
             get { return rectangleElement;}
         }

         public override BooElement Element
         {
             set { rectangleElement = (BooRectangleElement)value; }
             get { return rectangleElement; }
         }

         public override BooTextShapesBaseElement TextShapesBaseElement
         {
             get { return rectangleElement; }
         }

         public override Shapes.Shape Shape
         {
             get { return rectangle; }
         }

         public BooRectangle(BooRectangleElement element, SaveForRedoUndo saveForRedoUndo)
             : base(element)
         {
              this.rectangleElement = element;
              InitOriginal();            
              base.saveForRedoUndo = saveForRedoUndo;
              Focus.InitFocusEvent(this);
          }

         public BooRectangle(BooRectangleElement element)
             : base(element)
        {
            this.rectangleElement = element;
            InitOriginalForThumbNails();
        }

          public override void InitShape()
          {
              rectangle = new Shapes.Polygon();
              rectangle.Points = BooShapesPoints.CopyPointCollection(rectangleElement.Points);
              rectangle.ManipulationMode = ManipulationModes.All;
          }

          public override void ReSizeUI(double x, double y)
          {
              if (rectangleElement.ElementTransform.Width + x < 50 || rectangleElement.ElementTransform.Height + y < 50)
              {
                  return;
              }

              rectangleElement.ElementTransform.Width = rectangleElement.ElementTransform.Width + x;
              rectangleElement.ElementTransform.Height = rectangleElement.ElementTransform.Height + y;

              rectangleElement.PropertyChanged("Shape");
          }

          public override void ReMargin(double x, double y)
          {
              this.Element.ElementTransform.Translate.X += x;
              this.Element.ElementTransform.Translate.Y += y;
          }


          public override void ApplySize()
          {
              base.ApplySize();
              rectangleElement.ShapeWidth = rectangleElement.ElementTransform.Width;
              rectangleElement.ShapeHeight = rectangleElement.ElementTransform.Height;

              //this.rectangle.Width = rectangleElement.ElementTransform.Width;
              //this.rectangle.Height = rectangleElement.ElementTransform.Height;

              FullGrid.Width = rectangleElement.ElementTransform.Width;
              FullGrid.Height = rectangleElement.ElementTransform.Height;

              //BooCanvas.Width = rectangleElement.ElementTransform.Width;
              //BooCanvas.Height = rectangleElement.ElementTransform.Height;

              CenterStack.Width = rectangleElement.ElementTransform.Width;
              //CenterStack.MaxHeight = rectangleElement.ElementTransform.Height;


              this.TextBox.Width = rectangleElement.ElementTransform.Width;
              rectangleElement.TextWidth = rectangleElement.ElementTransform.Width;
             // this.TextBox.MaxHeight = rectangleElement.ElementTransform.Height;
             // rectangleElement.TextMaxHeight = rectangleElement.ElementTransform.Height;


              Focus.FocusElls.ScopeRectangle.Width = rectangleElement.ElementTransform.Width;
              Focus.FocusElls.ScopeRectangle.Height = rectangleElement.ElementTransform.Height;
              Focus.SetFocuseEllipseMargin(Focus.FocusElls.ScopeRectangle.Width, Focus.FocusElls.ScopeRectangle.Height);

              Point[] pt = new Point[rectangleElement.Points.Count];
              PointCollection pts = new PointCollection();
              rectangleElement.Points.CopyTo(pt, 0);
              pt[0].X = 0;
              pt[0].Y = 0;
              pt[1].X = rectangleElement.ElementTransform.Width;
              pt[1].Y = 0;
              pt[2].X = rectangleElement.ElementTransform.Width;
              pt[2].Y = rectangleElement.ElementTransform.Height;
              pt[3].Y = rectangleElement.ElementTransform.Height;
              pt[3].X = 0;
              pts.Add(pt[0]);
              pts.Add(pt[1]);
              pts.Add(pt[2]);
              pts.Add(pt[3]);
              rectangle.Points = pts;
              rectangleElement.Points = pts;
          }
     }
}
